package cn.jbolt.ec.retailer;

import cn.jbolt._admin.permission.CheckPermission;
import cn.jbolt._admin.permission.PermissionKey;
import cn.jbolt._admin.permission.UnCheckIfSystemAdmin;
import cn.jbolt.base.JBoltBaseController;
import cn.jbolt.common.model.BecRetailerType;
import cn.jbolt.common.model.Permission;
import com.jfinal.aop.Inject;

@CheckPermission(PermissionKey.RETAILER_TYPE_ADMIN)
public class EcRetailerTypeAuthController extends JBoltBaseController {

    @Inject
    RetailerTypeService retailerTypeService;

    /**
     * 商家类型管理主页面
     */
    @CheckPermission(PermissionKey.RETAILER_TYPE_INDEX)
    public void index(){
        keepPara();
        set("pageData",retailerTypeService.get_retailer_type_page(getPageNumber(),getPageSize(),getKeywords(),getBoolean("isDelete",false)));
        set("deleteCount",retailerTypeService.get_retailer_type_deleteCount());
        render("index.html");
    }


    /**
     * 商家类型管理添加
     */
    @CheckPermission(PermissionKey.RETAILER_TYPE_ADD)
    public void add(){
        render("add_form.html");
    }

    /**
     * 商家类别管理 保存
     */
    public void save(){
        renderJson(retailerTypeService.save(getModel(BecRetailerType.class,"retailerType")));
    }


    /**
     * 商家类别管理 修改
     */
    @CheckPermission(PermissionKey.RETAILER_TYPE_MODIFY)
    public void modify(){
        set("retailerType",retailerTypeService.findById(getInt(0)));
        render("modify_form.html");
    }

    /**
     * 修改 商家类别  保存
     */
    public void update(){
        renderJson(retailerTypeService.update(getModel(BecRetailerType.class,"retailerType")));
    }


    /**
     * 删除 / 还原  商家类别
     */
    @CheckPermission({PermissionKey.RETAILER_TYPE_DELETE,PermissionKey.RETAILER_TYPE_RESTORE})
    public void delete_restore_retailer_type(){
        renderJson(retailerTypeService.delete_restore_retailer_type(getInt(0)));
    }

    /**
     * 切换  商家类别 是否有 首页资格
     */
    public void toggle_isrecommand(){
        renderJson(retailerTypeService.toggle_isrecommand(getInt(0)));
    }

}
